//开始调用Ajax
/*
url:要访问的链接   参数类型:String
paramMap:参数列表  参数类型:Map
callBack:回调接口  参数类型:js对象
注:callBack对象类一定要有onSuccess(ResultBean rb)方法和onFail(ResultBean rb)方法
*/
function AjaxStart(url, paramet, callBack) {

    //显示等待框
    wait.show();
    $.ajax({
        url: url,
        cache: false,
        type: 'get',
        dataType: "json",
        data: encodeURI(paramet),
        success: function (json) {
            if (json == null) {
                toast.show("服务器返回数据失败");
                return;
            }
            wait.dismiss();
            callBack(json);
        },
        error: function (rs) {
            toast.show("服务器故障!");
        }
    });
}

var ajax = new AjaxData();

function AjaxData() {
    var paramet = "";

    //获取产品列表
    this.getProductList = function (page, source, statuscfg, callback) {

        paramet = "currentpage=" + page + "&source=" + source + "&statuscfg=" + statuscfg;
        AjaxStart(ajaxUrl.getProductList, paramet, callback);
    }

    //修改产品状态
    this.changeState = function (id, source, statuscfg, callback) {

        paramet = "id=" + id + "&source=" + source + "&statuscfg=" + statuscfg;
        AjaxStart(ajaxUrl.changeState, paramet, callback);
    }

    //修改密码
    this.modifyPwd = function (oldPwd, newPwd, callback) {

        paramet = "oldPwd=" + oldPwd + "&newPwd=" + newPwd;
        AjaxStart(ajaxUrl.modifyPwd, paramet, callback);
    }

    //获取分类列表
    this.getGoupList = function (parentId1, parentId2, callback) {

        paramet = "parentId1=" + parentId1 + "&parentId2=" + parentId2;
        AjaxStart(ajaxUrl.getGoupList, paramet, callback);
    }

    //修改产品是属于微商还是属于产品
    this.updateSource = function (id, source, callback) {

        paramet = "id=" + id + "&source=" + source;
        AjaxStart(ajaxUrl.updateSource, paramet, callback);
    }

    //模板申请
    this.modelApply = function (cls, index, callback) {

        paramet = "cls=" + cls + "&index=" + index;
        AjaxStart(ajaxUrl.modelApply, paramet, callback);
    }


    //添加分类
    this.addGroup = function (name, parentId1, parentId2, callback) {

        paramet = "name=" + name + "&parentId1=" + parentId1 + "&parentId2=" + parentId2;
        AjaxStart(ajaxUrl.addGroup, paramet, callback);
    }

    //删除分类
    this.delGroup = function (id, callback) {

        paramet = "id=" + id;
        AjaxStart(ajaxUrl.delGroup, paramet, callback);
    }

    //更新分类名
    this.updateName = function (id, name, callback) {

        paramet = "id=" + id + "&name=" + name;
        AjaxStart(ajaxUrl.updateName, paramet, callback);
    }

    //忘记密码
    this.forgetPwd = function (username, email, validate, callback) {

        paramet = "username=" + username + "&email=" + email + "&validate=" + validate;
        AjaxStart(ajaxUrl.forgetPwd, paramet, callback);
    }
}


var ajaxUrl = new Url();
function Url() {
    this.getProductList = "ajax/ProductList.ashx?GetList";
    this.changeState = "ajax/ProductList.ashx?ChangeState";
    this.updateSource = "ajax/ProductList.ashx?UpdateSource";
    this.modifyPwd = "../ajax/Shop.ashx?ModifyPwd";
    this.forgetPwd = "../ajax/Shop.ashx?ForgetPwd";
    this.getGoupList = "ajax/Group.ashx?GetList";
    this.addGroup = "ajax/Group.ashx?Add";
    this.delGroup = "ajax/Group.ashx?Delete";
    this.updateName = "ajax/Group.ashx?UpdateName";
    this.modelApply = "ajax/template.ashx?Apply";
}


